#!/bin/bash -e

function info() {
echo Usage: `basename $0` '[-l in.bed -m(somatic) -g(single_cell)] (in.vcf)s'
exit 65
}

while getopts ":p:l:mgh" opts
do
case $opts in
	m) somatic=T;;
	g) single_cell=T;;
	l) interval=$OPTARG;;
	p) out_prefix=$OPTARG;;
	\?) info;;
esac
done
shift $(($OPTIND - 1))

test $# -lt 1 && info


. /mnt/ilustre/app/medical/tools/.var

if test $# -gt 1; then

combine_vcfs.sh -p$out_prefix $@

else
ln -sf $1 $out_prefix.combine.vcf
fi


# if test "$somatic" = "T"; then
	# echo filter_high_low.pl somatic
	# filter_high_low.pl $out_prefix.combine.vcf $out_prefix.high.txt $out_prefix.low.txt $out_prefix.header.txt
# else
	# echo filter_pass.pl
	# filter_pass.pl $out_prefix.combine.vcf $out_prefix.high.txt $out_prefix.low.txt $out_prefix.header.txt
# fi


if test "$somatic" = "T"; then
	echo filter_high_low.pl somatic
	filters.pl -m $out_prefix.combine.vcf $out_prefix.high.txt $out_prefix.low.txt $out_prefix.header.txt
elif test -n "$single_cell"; then
	echo filter_pass.pl single_cell
	filters.pl -g $out_prefix.combine.vcf $out_prefix.high.txt $out_prefix.low.txt $out_prefix.header.txt
else
	echo filter_pass.pl germline bulk
	filters.pl $out_prefix.combine.vcf $out_prefix.high.txt $out_prefix.low.txt $out_prefix.header.txt
fi


cat $out_prefix.header.txt $out_prefix.high.txt > $out_prefix.high.vcf
cat $out_prefix.header.txt $out_prefix.low.txt > $out_prefix.low.vcf

rm $out_prefix.high.txt $out_prefix.low.txt $out_prefix.header.txt

. $cmd_done

